package main

import (
	"im/controller"
	"im/model"

	"im/utils"
	"log"

	"github.com/gin-gonic/gin"
)

func main() {

	db, err := utils.InitDB()
	if err != nil {
		log.Println("connect mysql failed", err)
	}
	if err = db.AutoMigrate(new(model.User), new(model.ChatGroup),
		new(model.Contact)); err != nil {
		log.Fatal("数据库迁移失败...", err)
	}
	app := gin.Default()

	v1 := app.Group("/v1")
	contact := v1.Group("/contact")
	chat := v1.Group("/chatfriend")
	initApi(v1, contact, chat)

	app.Run(":8888")
}

func initApi(v1, contact, chat *gin.RouterGroup) {

	controller.NewUserController().StartInitUserController(v1)
	controller.NewUserOperation().StartInitUserOperation(contact)
	controller.NewChat().StartInitChat(chat)
}
